#include<iostream>
#include<algorithm>
using namespace std;
int arr[3][2];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> arr[i][j];
		}
	}
	int s1, s2, s3;
	int n1, n2, n3;
	if (n % arr[0][0] == 0) {
		n1 = n / arr[0][0];
	}
	else {
		n1 = n / arr[0][0] + 1;
	}
	s1 = n1 * arr[0][1];
	if (n % arr[1][0] == 0) {
		n2 = n / arr[1][0];
	}
	else {
		n2 = n / arr[1][0] + 1;
	}
	s2 = n2 * arr[1][1];
	if (n % arr[2][0] == 0) {
		n3 = n / arr[2][0];
	}
	else {
		n3 = n / arr[2][0] + 1;
	}
	s3 = n3 * arr[2][1];
	int m = s1;
	cout << s1 << " " << s2 << " " << s3 << endl;
	m = min(m, s2);
	m = min(m, s3);
	cout << m << endl;
	return 0;
}